package com.free.front.bf.service;

import com.deco.domain.vo.store.StoreShopVo;
import com.deco.domain.vo.sys.ChinastatesVo;
import com.deco.domain.vo.sys.CmsAdvTypeVo;
import com.deco.domain.vo.sys.CmsAdvVo;
import com.deco.service.store.StoreShopService;
import com.deco.service.sys.ChinastatesService;
import com.deco.service.sys.CmsAdvService;
import com.deco.service.sys.CmsAdvTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 功能概述:
 * </p>
 * <p>
 * 功能详述:
 * </p>
 */
@Component
public class StoreShopNetBf {


	// banner
	private static final String BANNER = "fixBanner";

	@Autowired
	private CmsAdvTypeService cmsAdvTypeService;

	@Autowired
	private CmsAdvService cmsAdvService;

	@Autowired
	private ChinastatesService chinastatesService;

	@Autowired
	private StoreShopService storeShopService;
	
	public Map<String, Object>  getStoreShopData(Integer type, String prov, String city,
			String area) {

		Map<String, Object> res = new HashMap<>();
		CmsAdvTypeVo advType = cmsAdvTypeService.selectByCode(BANNER);
		if (advType != null) {
			CmsAdvVo vo = new CmsAdvVo();
			vo.setTypeId(advType.getId());
			List<CmsAdvVo> cmsAdvList = cmsAdvService.getCmsAdvVoList(vo,
					" idx ");
			if (cmsAdvList != null && cmsAdvList.size() > 8) {
				cmsAdvList = cmsAdvList.subList(0, 8);
			}
			res.put("bannerList", cmsAdvList);
		}
	        type = type == null ? 0 : type;
	        res.put("type",type);
	        
	        res.put("prov",prov);
	        res.put("city",city);
	        res.put("area",area);
	        
	        Map<String, ChinastatesVo> areaMap = chinastatesService.getAll();
	        
	        List<StoreShopVo> list = storeShopService.queryProvList(type);
	        for(StoreShopVo shop : list){
	        	ChinastatesVo p = areaMap.get(shop.getProv());
	            shop.setProvName(p.getName());
	        }
	        res.put("list", list);
	        return res;
	}
    /*========================================================================*
     *                         Public Fields (公共属性)
     *========================================================================*/

	public List<StoreShopVo> queryStoreShopData(StoreShopVo shop) {
		return storeShopService.queryStoreShop(shop);
	}

    /*========================================================================*
     *                         Private Fields (私有属性)
     *========================================================================*/

    /*========================================================================*
     *                         Construct Methods (构造方法)
     *========================================================================*/

    /*========================================================================*
     *                         Public Methods (公有方法)
     *========================================================================*/

    /*========================================================================*
     *                         Private Methods (私有方法)
     *========================================================================*/
}
